package com.boot.unity.api.modules.train.dao;

import com.alibaba.fastjson.JSONObject;
import com.boot.unity.api.modules.train.entity.Stu;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StuDao {
    // and a.`status` = '0'
    @Select("SELECT t.* from train_stu t,train_student a " +
            "where a.student_id = t.student_id " +
            "and t.tfstatus not like '%1%' and t.step = 'F' and t.card_no = #{cardNo} order by t.add_time desc limit 0,1")
    Stu getStuByCardNo(@Param("cardNo") String cardNo);

    @Delete("delete from train_base_file where cardno = #{cardId}")
    int delBaseImgForCardId(@Param("cardId") String cardId);

    @Select("SELECT * FROM `train_base_file` where file is not null and cardno = #{cardId}")
    List<JSONObject> queryBaseImgForCardId(@Param("cardId") String cardId);


    @Select("select * from train_stu where step = 'F' and tfstatus not like '%1%' train_type = #{trainType} and card_no = #{cardNo}")
    List<Stu> queryPayOkNoTf(@Param("cardNo") String cardNo,@Param("trainType") String trainType);


    @Select("select * from train_stu where step = 'F' and tfstatus not like '%1%' and train_type = #{trainType} and card_no = #{cardNo} order by add_time desc limit 0,1")
    Stu queryStuPayOkNoTf(@Param("cardNo") String cardNo,@Param("trainType") String trainType);


    @Update("update train_stu set student_id = #{studentId} where step = 'F' and tfstatus not like '%1%' train_type = #{trainType} and card_no = #{cardNo} ")
    int updateStuForStudentId(@Param("studentId") String studentId,@Param("cardNo") String cardNo,@Param("trainType") String trainType);

    @Update("update train_stu set student_id = #{studentId} where id = #{id}")
    int updateStudentIdById(@Param("studentId") String studentId,@Param("id") String id);

    Stu getByCardNo(@Param("cardNo") String cardNo,@Param("type") String type);


    @Select("SELECT * from train_stu where step = 'F' and card_no = #{cardNo} ORDER BY add_time DESC LIMIT 0,1")
    Stu getStuDetailByCardNo(@Param("cardNo") String cardNo);

    Stu getByCardNoStopJS(@Param("cardNo") String cardNo,@Param("type") String type);


    @Select("select * from train_stu")
    List<Stu> list();

    @Update("update train_stu set name=#{name},gender=#{gender},address=#{address}," +
            "nationality=#{nationality},mobile=#{mobile},nation=#{nation}," +
            "learning_categories=#{learningCategories} where id = #{id}")
    int updateStu(Stu stu);


    //更新缴费信息的姓名
    @Update("update train_payinfo set stu_name = #{name} where card_no = #{cardNo}")
    int updatePayInfoName(@Param("cardNo") String cardNo,@Param("name") String name);
}
